// 导入数据库操作模块
const db = require('../db/index');
// 导入上传文件模块
const multer = require('multer');
const req = require('express/lib/request');

// 文件存储配置
const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, './api/file');
    },
    filename: (req, file, cb) => {
        let type = file.originalname.replace(/.+\./, '.'); //截取文件后缀
        cb(null, Date.now() + type); //时间戳+后缀
    }
});

// 实例化出的上传文件对象
const upload = multer({ storage: storage }).array('file', 10);

// 上传文件
exports.uploadImg = (req, res) => {
    upload(req, res, function (err) {
        console.log(req.files);
        res.send(req.files);
    });
}